package com.union.core.sys.model;

import java.util.List;

import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;

import org.apache.log4j.Logger;

import com.hnjowe.util.ComUtil;
import com.union.core.organization.model.Personnel;

/**
 * 数据模型: 系统管理帐号
 * <p>Copyright: Copyright (c) 2008</p>
 * <p>Company: Hainan Jowe Technology Ltd</p>
 * @author Xiuwu.Wang
 * @version 2.0
 */
public class SysManager implements HttpSessionBindingListener {
	
	private static Logger log = Logger.getLogger(SysManager.class.getName());

	private int MANAGER_ID; 			// 帐号编号
	private String MANAGER_NAME; 		// 帐号登陆帐号
	private String MANAGER_PWD; 		// 帐号登陆密码
	private int MANAGER_STATUS; 		// 帐号状态
	private String MODULE_MGR_PURVIEW; 	// 功能模块管理权限
	private String MANAGER_DESC; 		// 帐号描述
	private int LOGIN_TIMES; 			// 登陆次数
	private String LAST_LOGIN_IP; 		// 最后登录IP
	private String LAST_LOGIN_TIME; 	// 最后登录时间
	private int MANAGER_WEIGHT;         // 账户权重


	private String MANAGER_ROLES;		// 账户角色
	private int PERSONNEL_ID;           // 对应人员ID

	private boolean online_flag;		//在线状态,true-在线,false-离线
	private SysManager sysManager;
	private String sessionId;			//存储session id
	private Personnel PERSONNEL;        //对应人员信息
	private List<String> allPower;

	public List<String> getAllPower() {
		return allPower;
	}

	public void setAllPower(List<String> allPower) {
		this.allPower = allPower;
	}

	private SysManagerSessionList sysmanagerSessionList = SysManagerSessionList.getInstance();

	/**
	 * 绑定session
	 */
	public void valueBound(HttpSessionBindingEvent e) {
		this.setSysManager((SysManager)e.getValue());
		sysmanagerSessionList.addSession(e.getSession());  		//将管理用户session放入队列
		log.info("#管理用户[" + sysManager.getMANAGER_NAME() + "]登入后台系统, 在线管理用户数：" + sysmanagerSessionList.getSessionCount());
	}

	/**
	 * 解除session
	 */
	public void valueUnbound(HttpSessionBindingEvent e) {
		try{
			sysmanagerSessionList.removeSession(e.getSession());	//将管理用户session移出队列
			log.info("#管理用户[" + sysManager.getMANAGER_NAME() + "]退出后台系统, 在线管理用户数：" + sysmanagerSessionList.getSessionCount());
		}catch(Exception ex){
		}
	}

	public String getLAST_LOGIN_IP() {
		return LAST_LOGIN_IP;
	}

	public String getLAST_LOGIN_TIME() {
		return LAST_LOGIN_TIME;
	}

	public int getLOGIN_TIMES() {
		return LOGIN_TIMES;
	}

	public String getMANAGER_DESC() {
		return MANAGER_DESC;
	}

	public int getMANAGER_ID() {
		return MANAGER_ID;
	}

	public String getMANAGER_NAME() {
		return MANAGER_NAME;
	}

	public String getMANAGER_PWD() {
		return MANAGER_PWD;
	}

	public int getMANAGER_STATUS() {
		return MANAGER_STATUS;
	}



	public void setLAST_LOGIN_IP(String LAST_LOGIN_IP) {
		this.LAST_LOGIN_IP = LAST_LOGIN_IP;
	}

	public void setLAST_LOGIN_TIME(String LAST_LOGIN_TIME) {
		this.LAST_LOGIN_TIME = LAST_LOGIN_TIME;
	}

	public void setLOGIN_TIMES(int LOGIN_TIMES) {
		this.LOGIN_TIMES = LOGIN_TIMES;
	}

	public void setMANAGER_DESC(String MANAGER_DESC) {
		this.MANAGER_DESC = MANAGER_DESC;
	}

	public void setMANAGER_ID(int MANAGER_ID) {
		this.MANAGER_ID = MANAGER_ID;
	}

	public void setMANAGER_NAME(String MANAGER_NAME) {
		this.MANAGER_NAME = MANAGER_NAME;
	}

	public void setMANAGER_PWD(String MANAGER_PWD) {
		this.MANAGER_PWD = MANAGER_PWD;
	}

	public void setMANAGER_STATUS(int MANAGER_STATUS) {
		this.MANAGER_STATUS = MANAGER_STATUS;
	}


	public String getMODULE_MGR_PURVIEW() {
		return MODULE_MGR_PURVIEW;
	}

	public void setMODULE_MGR_PURVIEW(String mODULEMGRPURVIEW) {
		MODULE_MGR_PURVIEW = mODULEMGRPURVIEW;
	}

	public SysManager getSysManager() {
		return sysManager;
	}

	public void setSysManager(SysManager sysManager) {
		this.sysManager = sysManager;
	}

	public boolean isOnline_flag() {
		return online_flag;
	}

	public void setOnline_flag(boolean onlineFlag) {
		online_flag = onlineFlag;
	}

	public String getSessionId() {
		return sessionId;
	}

	public void setSessionId(String sessionId) {
		this.sessionId = sessionId;
	}
	public String getMANAGER_ROLES() {
		return MANAGER_ROLES;
	}

	public void setMANAGER_ROLES(String mANAGERROLES) {
		MANAGER_ROLES = mANAGERROLES;
	}
	public int getPERSONNEL_ID() {
		return PERSONNEL_ID;
	}

	public void setPERSONNEL_ID(int pERSONNELID) {
		PERSONNEL_ID = pERSONNELID;
	}

	public Personnel getPERSONNEL() {
		if(PERSONNEL == null && PERSONNEL_ID > 0){
			PERSONNEL = ComUtil.getPersonnelService().query(PERSONNEL_ID);
		}
		return PERSONNEL;
	}

	public void setPERSONNEL(Personnel pERSONNEL) {
		PERSONNEL = pERSONNEL;
	}
	public int getMANAGER_WEIGHT() {
		return MANAGER_WEIGHT;
	}

	public void setMANAGER_WEIGHT(int mANAGERWEIGHT) {
		MANAGER_WEIGHT = mANAGERWEIGHT;
	}
}